var list_input = new Array('password','new_password','confirm_new_password','verify_image');
/* #################################### xu ly password #############################*/
var chkPassErr = 0;
var chkConfirmPassErr = 0;
$("#password").focus( function() {	
	//Update check							 
	if(check_show_keyboard()) return true;
	//End								  							   
	if(this.value == ''){
		hideError('#password');
	}else{
	}	
} );
$("#password").blur( function(){  
	//Update check							 
	if(check_show_keyboard()) return true;
	//End								  
	return check_password(this);
} );
function check_password(obj){	
	if(!checkVietNam(obj.value)){
		return showError(obj,Password_Error[0]);
	}
	if(!checkLen(obj.value,4,32)) {
		return showError(obj,Password_Error[1]);
    } 
	if(obj.value) {
		checkValid("#password_icon");
	}
	return hideError(obj);
}

$("#new_password").focus( function() {	
	//Update check							 
	if(check_show_keyboard()) return true;
	//End								  								   
	if(this.value == ''){
		hideError("#new_password");
		$("#new_password_tr_note").addClass("td_note");
		$('#new_password_note').html(PASWORD_DESCRIPTION);
		$("#new_password_note").show();
	}else{

	}
} );
$("#new_password").blur( function(){
	if(this.value == ''){
		return;	
	}
	//Update check							 
	if(check_show_keyboard()) return true;
	//End								  
    $('#new_password_note').hide();
	hideError("#new_password");
	if(this.value.length > 6){
		show_Meta(this.value);
	}
	check_new_password(this);
} );
$("#new_password").change( function(){
	$("#confirm_new_password").val('');
} );
function check_new_password(obj){
	if($('#new_password').val() == ''){
		return true;
	}
	if(!checkVietNam($('#new_password').val())){
		showError(obj,Password_Error[0]);
		return false
	}	
	if(!checkLen($('#new_password').val(),6,32)) {
		showError(obj,PASSWORD_ERR_NEW_LEN);
		return false;
    }
	//update new password
	if(!STRONG_PASSWORD){
		showError(obj,PASSWORD_ERR_NEW);
		return false;
	}
	//end
	if(obj.value) {
		checkValid("#new_password_icon");
	}	
	return true;
}
$("#new_password").keyup( function() {
	//Update check							 
	if(check_show_keyboard()) return true;
	//End								  					   
	if(!checkVietNam(this.value)){
		chkPassErr = 1;
		resetMeta();
		return showError(this,Password_Error[0]);
	}else{
		if($("#sPassWord1_note").css('display') == 'none'){
			chkPassErr = 0;
			hideError(this);
		}
	}
	if(this.value.length < 6){
		resetMeta();
		return false;
	}	
	show_Meta(this.value);
} );
$("#confirm_new_password").focus( function() {
	//Update check							 
	if(check_show_keyboard()) return true;
	//End										   
	if(this.value == ''){
		hideError("#confirm_new_password")
	}else{
	}	
} );
$("#confirm_new_password").blur( function(){
	//Update check							 
	if(check_show_keyboard()) return true;
	//End										   
	if(this.value == ''){
		hideError("#confirm_new_password")
	}else{
		return check_confirm_new_password(this);
	}		
} );
function check_confirm_new_password(obj){	
	if(!checkLen($("#new_password").val(),6,32)) {
		return false;
    }
	if($("#new_password").val() != $("#confirm_new_password").val()){
		return showError(obj,Password_Error[3]);
	}
	if(obj.value) {
		checkValid("#confirm_new_password_icon");
	}
	return hideError(obj);	
}
function check_require_field(){
	var check_valid = 0;
	var list_input_require = new Array('password','new_password','confirm_new_password','sVerifyCode');	
	for(var i=0;i<list_input_require.length;i++){
		if($('#'+list_input_require[i]).val()  == ''){
			$('#'+list_input_require[i]+'_tr').addClass('tr_error');
			showError('#'+list_input_require[i],Require_Error);
			check_valid = 1;
		}
	}
	if(!check_new_password("#new_password")) {
		check_valid = 1;	
	}
	if($("#new_password").val() != $("#confirm_new_password").val()){
		showError('confirm_new_password',Password_Error[4]);
		check_valid = 1;
	}
	var frm =	document.frmChangepass ;
	var verify_code	= 	frm.elements["sVerifyCode"];
	if(verify_code){
		if($("#sVerifyCode").val().length<1){
			showError("#sVerifyCode",Require_Error);
			check_valid = 1;
		} else if(!checkImageSecurity(verify_code,6,true)) {
			showError("#sVerifyCode",Verify_Error[1]);
			check_valid = 1;
		}
	}
	if(check_valid)
		return false;
	else
		return true;
}
function on_submit(){	
	if(!check_require_field() || $('#password_err').css('display') != 'none' || $('#new_password_err').css('display') != 'none'  || $('#confirm_new_password_err').css('display') != 'none' ){
		return false;
	}
	else{
		var frm =	document.frmChangepass ;
		var verify_code	= 	frm.elements["sVerifyCode"];
		if(verify_code){
			if($('#sVerifyCode_err').css('display') != 'none'){
				return false;	
			}
		}
		return true;
	}
}